//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.tool.commons;

import com.ruoyi.live.tool.assistant.IProcessBean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class IProcess {
    public IProcess() {
    }

    public static IProcessBean execProcess(String commend, Boolean waitFinish) throws Exception {
        return execProcess(commend, waitFinish, true, true);
    }

    public static IProcessBean execProcess(String commend, Boolean waitFinish, Boolean notesInputStream, Boolean notesErrorStream) throws Exception {
        Boolean a = notesInputStream;
        Boolean b = notesErrorStream;
        IProcessBean processBean = new IProcessBean();
        processBean.setResult(false);
        Process process = null;
        String var8 = "";

        IProcessBean var20;
        try {
            process = Runtime.getRuntime().exec(commend);
            if (waitFinish) {
                InputStream is1 = process.getInputStream();
                InputStream is2 = process.getErrorStream();
                (new IProcessInputStream(is1, a, processBean)).start();
                (new IProcessErrorStream(is2, b, processBean)).start();
                process.waitFor();
                process.destroy();
            }

            processBean.setResult(true);
            var20 = processBean;
        } catch (Exception var18) {
            throw var18;
        } finally {
            try {
                if (process != null) {
                    process.getErrorStream().close();
                    process.getInputStream().close();
                    process.getOutputStream().close();
                }
            } catch (Exception var17) {
                throw var17;
            }

        }

        return var20;
    }

    final static class IProcessInputStream extends Thread {
        private InputStream inputStream1;
        private Boolean flag1;
        private IProcessBean processBean;
        IProcessInputStream(InputStream inputStream1, Boolean flag1, IProcessBean processBean) {
            this.inputStream1 = inputStream1;
            this.flag1 = flag1;
            this.processBean = processBean;
        }

        public void run() {
            BufferedReader br1 = new BufferedReader(new InputStreamReader(this.inputStream1));

            try {
                String line1 = null;

                while((line1 = br1.readLine()) != null) {
                    if (this.flag1) {
                        this.processBean.appendInputStream(line1);
                    }
                }
            } catch (IOException var11) {
                var11.printStackTrace();
            } finally {
                try {
                    this.inputStream1.close();
                } catch (IOException var10) {
                    var10.printStackTrace();
                }

            }

        }
    }

    final static class IProcessErrorStream extends Thread {
        private InputStream inputStream2;
        private Boolean flag2;
        private IProcessBean processBean;
        IProcessErrorStream(InputStream inputStream2, Boolean flag2, IProcessBean processBean) {
            this.inputStream2 = inputStream2;
            this.flag2 = flag2;
            this.processBean = processBean;
        }

        public void run() {
            BufferedReader br2 = new BufferedReader(new InputStreamReader(this.inputStream2));

            try {
                String line2 = null;

                while((line2 = br2.readLine()) != null) {
                    if (this.flag2) {
                        this.processBean.appendErrorStream(line2);
                    }
                }
            } catch (IOException var11) {
                var11.printStackTrace();
            } finally {
                try {
                    this.inputStream2.close();
                } catch (IOException var10) {
                    var10.printStackTrace();
                }

            }

        }
    }

}


